package com.lasertd.view;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;
import com.lasertd.model.Area;
import com.lasertd.model.Field;

public class AreaRenderer {

	private Area area;
	
	private OrthographicCamera cam;
	ShapeRenderer debugRenderer = new ShapeRenderer();
	
	public AreaRenderer(Area area) {
		this.area = area;
		
		this.cam = new OrthographicCamera(16, 16);
		this.cam.position.set(8, 8, 0);
		this.cam.update();
	}
	
	public void render() {
		// render blocks
		this.debugRenderer.setProjectionMatrix(this.cam.combined);
		
		for (Field field : this.area.getFields()) {
			Rectangle rect = field.getBounds();
			
			float x1 = field.getPos().x + rect.x;
			float y1 = field.getPos().y + rect.y;

			if( field.isStart() )
			{
				this.debugRenderer.begin(ShapeType.Filled);
				this.debugRenderer.setColor(new Color(0, 1, 1, 1));
				this.debugRenderer.rect(x1, y1, rect.width, rect.height);
				this.debugRenderer.end();
			}
			else if( field.isEnd() )
			{
				this.debugRenderer.begin(ShapeType.Filled);
				this.debugRenderer.setColor(new Color(1, 0, 1, 1));
				this.debugRenderer.rect(x1, y1, rect.width, rect.height);
				this.debugRenderer.end();
			}
			else if( !field.isBuildable() && !field.isStart() && !field.isEnd() )
			{
				this.debugRenderer.begin(ShapeType.Filled);
				this.debugRenderer.setColor(new Color(1, 0, 0, 1));
				this.debugRenderer.rect(x1, y1, rect.width, rect.height);
				this.debugRenderer.end();
			}
			else {
				this.debugRenderer.begin(ShapeType.Line);
				this.debugRenderer.setColor(new Color(1, 1, 1, 1));
				this.debugRenderer.rect(x1, y1, rect.width, rect.height);
				this.debugRenderer.end();	
			}
			
			
			
		}
		
		
		
		
	}
	
}
